<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateConfirmationsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('confirmations', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->string('request_type')->unsigned()->comment('Тип запроса');
            $table->foreign('request_type')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');

            $table->string('confirm_type')->unsigned()->comment('Тип подтверждения');
            $table->foreign('confirm_type')->references('key')->on('types')->onDelete('restrict')->onUpdate('restrict');

            $table->integer('code')->comment('Код подтверждения');
            $table->string('value')->comment('Кому отправлено подтверждение');

            $table->timestamps();

            $table->unique(['request_type', 'confirm_type', 'value']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('confirmations');
    }
}
